trigger AutoIdentifyRecordtype on Order__c (before insert) {
    list<recordtype> rlist=new list<recordtype>();
    id returnorder;
    id freegoods;
    id normal;
    
    rlist=[select id,DeveloperName from recordtype where sobjecttype=:'order__c' and ( DeveloperName=:'FreeGoodsOrder' or DeveloperName=:'NormalOrder' or DeveloperName=:'ReturnOrder')];

    for(recordtype rt:rlist){                            //匹配recordtypeid
        if(rt.DeveloperName=='freegoodsorder'){
            freegoods=rt.id;
        }else if(rt.DeveloperName=='normalorder'){
            normal=rt.id;
        }else if(rt.DeveloperName=='returnorder'){
            returnorder=rt.id;
        }
    }
    
    for(order__c t:trigger.new){                    //recordtype赋值
    
        if(t.OrderType__c=='常规'){
            t.recordtypeid=normal;
        }else if(t.ordertype__c=='退货'){
            t.recordtypeid=returnorder;
        }else if(t.ordertype__c=='免费产品'){
            t.recordtypeid=freegoods;
        }
    }
    
    
}